import ajax from '../../js/ajax.js';

let txtemail = document.getElementById('txtemail');
let txtinfo = document.getElementById('txtinfo');
let btninfo = document.getElementById('btninfo');
let btnok = document.getElementById('btnok');

//#region 邮箱登入
btninfo.addEventListener('click', () => {
  ajax.send(
    '/tool/sendEmailCode',
    {
      email: txtemail.value,
    },
    (data) => {
      showToast(data.message);
    }
  );
});

btnok.addEventListener('click',()=>{
  if (txtinfo.value.trim() == '') {
    showToast('验证码不能为空');
    return;
  }

  let cs = {
    info: txtinfo.value,
    email: txtemail.value,
  };

  ajax.send('/user/auth/emailLogin', cs, (data) => {
    showToast(data.message); 
  });
   //成功跳转
  location.href='./ym.html';
})
//#endregion






//#region 公用的轻提示对话框

let liveToast = document.getElementById('liveToast');
let liveToastMessing = document.querySelector('#liveToast .toast-body');

const toast = new bootstrap.Toast(liveToast);

function showToast(message) {
  liveToastMessing.innerHTML = message;
  toast.show();
}
//#endregion
